package com.luntan.adapter;

import java.util.ArrayList;
import java.util.List;

import com.luntan.activity.GoForumActivity;
import com.luntan.activity.GoforumItemActivity;
import com.luntan.bean.Forumbean;
import com.luntan.utils.Utils;
import com.luntan.view.R;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewAdapters extends BaseAdapter {

	private ViewHolder holder;
	private ArrayList<Forumbean> list=null;
	private Context context;
	private int i=0;
	public ListViewAdapters(Context context, ArrayList<Forumbean> list) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.listview_items, null);
			holder.text = (TextView) convertView.findViewById(R.id.text);
			holder.time=(TextView)convertView.findViewById(R.id.timetext);
			holder.contenttext=(TextView)convertView.findViewById(R.id.contenttext);
			holder.contentimage=(ImageView)convertView.findViewById(R.id.contentimage);
			holder.discussimagebutton=(ImageButton)convertView.findViewById(R.id.discussimagebutton);
			holder.discussimagebutton.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Log.e("hha", "discussimagebutton");	
					Intent intent=new Intent(context,GoforumItemActivity.class);
					Forumbean forum=new Forumbean();
					forum.setName(list.get(position).getName());
					forum.setContent(list.get(position).getContent());
					forum.setTime(list.get(position).getTime());
					ArrayList<Forumbean> lists=new ArrayList<Forumbean>();
					lists.add(forum);
					//对forum序列化可传递到下个activity
					context.startActivity(intent);	
				}
			});
			holder.execllentimagebutton=(ImageButton)convertView.findViewById(R.id.execllentimagebutton);
			holder.execllentimagebutton.setOnClickListener(new OnClickListener() {	
				@Override
				public void onClick(View v) {
			  Utils.i=Utils.i+1;
			  Log.e("Utils.i", Utils.i+"");
				}
			});
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.text.setText(list.get(position).getName());
		holder.contenttext.setText(list.get(position).getContent());
		holder.time.setText(list.get(position).getTime());
//		holder.execllenttextview.setText(Utils.i);
		return convertView;
	}

	private static class ViewHolder {
		TextView text,time,execllenttextview,contenttext,discusstext;
		ImageView frgureimage,contentimage;
		ImageButton execllentimagebutton,discussimagebutton,settopimage;
		
	}

}
